<template>
  <div class="top-menu">
    <el-menu mode="horizontal" text-color="#333">
      <template>
        <el-menu-item @click.native="openMenu()">
          <template slot="title">
            <i :class="item.icon"></i>
            <span>{{ item.label }}</span>
          </template>
        </el-menu-item>
      </template>
    </el-menu>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "top-menu",
  data() {
    return {
      activeIndex: "0",
      items: [],
      item: {
        icon: "el-icon-document",
        label: "首页",
        path: "/wel/index",
      },
    };
  },
  inject: ["index"],
  computed: {
    ...mapGetters(["tagCurrent", "menu"]),
  },
  methods: {
    openMenu() {
      const item = this.item;
      let itemActive,
        childItemActive = 0;
      if (item.path) {
        itemActive = item;
      } else {
        if (this.menu[childItemActive].length == 0) {
          itemActive = this.menu[childItemActive];
        } else {
          itemActive = this.menu[childItemActive].children[childItemActive];
        }
      }
      this.$router.push({
        path: this.$router.$avueRouter.getPath({
          name: itemActive.label,
          src: itemActive.path,
          // i18n: itemActive.meta.i18n
        }),
      });
    },
  },
};
</script>